from django.contrib.auth.models import Group, Permission
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser

from meiduo_admin.serializers.group import GroupSerializer
from meiduo_admin.serializers.permissions import PermissionSerializer
from meiduo_admin.utils import PageNum


class GroupView(ModelViewSet):
    serializer_class = GroupSerializer
    queryset = Group.objects.all()
    pagination_class = PageNum
    permission_classes = [IsAdminUser]

    def simple(self, request):
        """
        获取所有权限
        :param request:
        :return:
        """
        # 1.查询所有的权限
        data = Permission.objects.all()
        # 2.返回查询结果
        ser = PermissionSerializer(data, many=True)
        return Response(ser.data)